package utils;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import mvc.view.IView;
import mvc.view.forms.CMDIChild;


public class CDBDebug extends CMDIChild implements ActionListener, IView {
	private JTextField LogTextField;
	private JTextPane leftTextPane;
	private JTable table;
	
	public CDBDebug() {
		setCaption("Debug SQL");
		
		JPanel panel = new JPanel();
		panel.setPreferredSize(new Dimension(10, 40));
		getContentPane().add(panel, BorderLayout.SOUTH);
		panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
		
		LogTextField = new JTextField();
		panel.add(LogTextField);
		LogTextField.setColumns(10);
		
		JSplitPane splitPane = new JSplitPane();
		splitPane.setResizeWeight(0.5);
		getContentPane().add(splitPane, BorderLayout.CENTER);
		
		JPanel panel_1 = new JPanel();
		splitPane.setLeftComponent(panel_1);
		panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.Y_AXIS));
		
		leftTextPane = new JTextPane();
		leftTextPane.setText("SELECT * FROM DE_SUBS");
		panel_1.add(leftTextPane);
		
		JPanel panel_3 = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel_3.getLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		panel_1.add(panel_3);
		
		JButton executeLeft = new JButton("Execute");
		executeLeft.addActionListener(this);
		
		panel_3.add(executeLeft);
		
		JButton btnClear = new JButton("Clear");
		panel_3.add(btnClear);
		
		JPanel panel_2 = new JPanel();
		splitPane.setRightComponent(panel_2);
		panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.X_AXIS));
		
		table = new JTable();
		panel_2.add(new JScrollPane(table));
	}

	@Override
  public void actionPerformed(ActionEvent e) {
		long start = System.currentTimeMillis();
		
//		CDBGridModel model = new CDBGridModel(leftTextPane.getText(), -1);
//		model.loadPage();
	//	table.setModel(model);
		
		float elapsedTimeMillis = ((System.currentTimeMillis() - start) / 1000);
		
		LogTextField.setText("Elapsed time: " + Float.toString(elapsedTimeMillis) + " seconds");
  }

}
